import java.util.ArrayList;
import java.util.Random;

public class CardDemo {
    public final int INIT_CARD_NUM = 52;
    ArrayList<Card> list = new ArrayList<>(); //以牌为对象存入顺序表中

    //买牌
    public ArrayList<Card> Buy_Card() {
        int[] rank = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
        //A,2,3,4,5,6,7,8,9,10,J,Q,K

        String[] suit = {"♥", "♠", "♦", "♣"};
        for (String s : suit) {
            for (int k : rank) {
                list.add(new Card(s, k));
            }
        }
        return list;
    }

    private void Swap(int a, int b) {
        Card tmp1 = this.list.get(a);
        Card tmp2 = this.list.get(b);
        this.list.set(a, tmp2);
        this.list.set(b, tmp1);

    }

    public void shuffle() {
        Random random = new Random();
        int rand_num = 0;
        for (int i = 0; i < this.list.size(); i++) {
            rand_num = random.nextInt(this.list.size());
            Swap(i, rand_num);
        }
    }

    public void Draw() {
        //发牌：每个人轮流抓五张牌
        ArrayList<Card> card1 = new ArrayList<>();
        ArrayList<Card> card2 = new ArrayList<>();
        ArrayList<Card> card3 = new ArrayList<>();

        ArrayList<ArrayList<Card>> cards = new ArrayList<>();

        cards.add(card1);
        cards.add(card2);
        cards.add(card3);

        for (int i = 0; i < 5; i++) {
//          j 是人
            for (int j = 0; j < 3; j++) {
                cards.get(j).add(i,this.list.get(0));
                this.list.remove(0);
            }
        }

        System.out.println("第一个人揭牌如下：");
        System.out.println(card1);

        System.out.println("第二个人揭牌如下：");
        System.out.println(card2);

        System.out.println("第三个人揭牌如下：");
        System.out.println(card3);

    }
}